#! /usr/bin/env python
# coding=utf-8
import sys, os
if '..' not in sys.path:
    sys.path.append('..')

import unittest
from common.priviledge import *

class TestPermissionRepository(unittest.TestCase):
    def setUp(self):
        self.permissionRepository = PermissionRepository()
        pass
        
    def test_getMenu1(self):
        li = self.permissionRepository._getMenu1()
        self.assertTrue(len(li) > 0)
        for item in li:
            self.assertEqual(len(item['level']), 3)

    def test_getMenu(self):
        li = self.permissionRepository._getMenu('001')
        self.assertTrue(len(li) > 0)
        for item in li:
            self.assertEqual(len(item['level']), 6)

    def testGetFullMenu(self):
        result1 = self.permissionRepository.getFullMenu('/')
        result2 = self.permissionRepository.getFullMenu('/index/project/')
        for result in (result1, result2):
            menu1 = result['menu1']
            self.assertTrue(len(menu1) > 0)
            for item in menu1:
                self.assertEqual(len(item['level']), 3)
            menu2 = result['menu2']
            self.assertTrue(len(menu2) > 0)
            for item in menu2:
                self.assertEqual(len(item['level']), 6)
                self.assertTrue(len(item['children']) > 0)
                for innerItem in item['children']:
                    self.assertEqual(len(innerItem['level']), 9)




